/*
 * addon_intf.h
 *
 *  Created on: 2010-1-7
 *      Author: gavinkwoe
 */

#ifndef ADDON_DOWNLOAD_LOGIC_H_
#define ADDON_DOWNLOAD_LOGIC_H_

#include "addon_features.h"
#include "addon_std.h"
#include "addon_objbase.h"
#include "addon_command.h"
#include "system_define.h"
#include "DownloadManager.h"

//class CQLibProvider;
/*************************************************************************
* INTERFACE
*************************************************************************/

//extern unsigned int Previous_pageID;
struct __struct_download_logic_data
{
	unsigned int           pageid;
	unsigned short*           url;
	unsigned short*           actualurl;
	unsigned short*           bookname;
	unsigned short*           chaptername;
	unsigned short*           bookid;
	unsigned short            chapterid;
	unsigned short            maxchapter;
	unsigned short*           bookinfo;
};

struct __struct_download_logic_data;
typedef struct __struct_download_logic_data   download_logic_data_t;
typedef struct __struct_download_logic_data*  download_logic_ptr_t;

struct __struct_online_logic_data
{
	unsigned int           pageid;
	unsigned short*        url;
	unsigned short*        actualurl;
	unsigned short*        bookname;
	unsigned short*        chaptername;
	unsigned long          bookid;
	unsigned short         chapterid;
	unsigned short         maxchapter;
};

struct __struct_download_logic_data;
typedef struct __struct_download_logic_data   download_logic_data_t;
typedef struct __struct_download_logic_data*  download_logic_ptr_t;

struct __struct_addon_download_logic_data
{
	unsigned long		  ref_cnt;		// reference count
	download_logic_data_t logic_data;
	ADDON_REF(IObject)	  pBookDownloadManager;
	ADDON_REF(IObject)	  observer;
	ADDON_REF(IObject)	  downloadOperator;
	
	ADDON_REF(IObject)	  pImageDownloadManager;
	//unsigned short*       filename;
	//CQLibProvider*        iLib;
	unsigned short        currentchapterid;
	bool                  isDownload;
};

struct __struct_addon_download_logic_data;
typedef struct __struct_addon_download_logic_data   addon_download_logic_data_t;
typedef struct __struct_addon_download_logic_data *	addon_download_logic_data_ptr_t;

ADDON_INTERFACE_( IDownloadLogic, 1, IDownloadStatusObserver )
{
	__INHERIT_FROM( IDownloadStatusObserver )

	ADDON_METHOD( DownloadRequest )			( ADDON_REF(IObject) thiz, IN void* aData, IN void* aUrl);
	ADDON_METHOD( OnlineRequest )			( ADDON_REF(IObject) thiz, IN void* aData, IN void* aUrl,IN int pageid);
	ADDON_METHOD( ImageRequest )            ( ADDON_REF(IObject) thiz, IN unsigned long addr);
	ADDON_METHOD( ParseExtraData )			( ADDON_REF(IObject) thiz, IN void* aData );
	ADDON_METHOD( SetObserver )		        ( ADDON_REF(IObject) thiz, IN ADDON_REF(IObject) obsvr );
	ADDON_METHOD( Operate)                  ( ADDON_REF(IObject) thiz, IN unsigned short* filename);
	ADDON_METHOD( Delete)                   ( ADDON_REF(IObject) thiz, IN unsigned short* filename,IN bool deletefile);
	ADDON_METHOD( DeleteAll)                ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( StartAll)                 ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( PauseAll)                 ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( LaunchTask)               ( ADDON_REF(IObject) thiz, IN bool islaunchtask);
	ADDON_METHOD( Save)                     ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( OpenPreChapter)           ( ADDON_REF(IObject) thiz, IN int bof);
	ADDON_METHOD( OpenNextChapter)          ( ADDON_REF(IObject) thiz, IN int bof);
	ADDON_METHOD( OpenLocalNextChapter)     ( ADDON_REF(IObject) thiz, IN int bof);
	ADDON_METHOD( LoadNextChapter)          ( ADDON_REF(IObject) thiz, IN int bof);
	ADDON_METHOD( CancelOnline)             ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( CancelImageDownload)      ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( OpenCurrentChapter)       ( ADDON_REF(IObject) thiz);
	ADDON_METHOD( SetIsDownload)            ( ADDON_REF(IObject) thiz,IN bool isdownload);
	ADDON_METHOD( OpenCacheFile)            ( ADDON_REF(IObject) thiz, IN unsigned short* filename);
	ADDON_METHOD( AddDownloadRequest )		( ADDON_REF(IObject) thiz, IN char* filename, IN char* url);
};

/*************************************************************************
* DECLARATION
*************************************************************************/

#if defined(__cplusplus)
extern "C" {
#endif	// #if defined(__cplusplus)

ADDON_IMPORT ADDON_REF(IObject)	addon_create_download_logic( void * reserved );

#if defined(__cplusplus)
}
#endif	// #if defined(__cplusplus)

/*************************************************************************
* MACRO
*************************************************************************/

#define IAddonDownloadLogic_VTBL( p )				    ADDON_GET_VTBL_(p, IDownloadLogic)
#define IAddonDownloadLogic_CALL( p, a )				IAddonDownloadLogic_VTBL(p)->a
#define IAddonDownloadLogic_DownloadRequest( p, a ,b)	IAddonDownloadLogic_CALL( p, DownloadRequest )( p, a ,b)
#define IAddonDownloadLogic_OnlineRequest( p, a ,b,c)	IAddonDownloadLogic_CALL( p, OnlineRequest )( p, a ,b,c)
#define IAddonDownloadLogic_ImageRequest( p, a )        IAddonDownloadLogic_CALL( p, ImageRequest )( p, a )
#define IAddonDownloadLogic_ParseExtraData( p, a )	    IAddonDownloadLogic_CALL( p, ParseExtraData )( p, a )
#define IAddonDownloadLogic_SetObserver( p, a )		    IAddonDownloadLogic_CALL( p, SetObserver )( p, a )
#define IAddonDownloadLogic_Operate( p, a )				IAddonDownloadLogic_CALL( p, Operate )( p, a )
#define IAddonDownloadLogic_Delete( p, a ,b)   	        IAddonDownloadLogic_CALL( p, Delete )( p, a ,b)
#define IAddonDownloadLogic_DeleteAll( p )		        IAddonDownloadLogic_CALL( p, DeleteAll )( p )
#define IAddonDownloadLogic_StartAll( p )		        IAddonDownloadLogic_CALL( p, StartAll )( p )
#define IAddonDownloadLogic_PauseAll( p )		        IAddonDownloadLogic_CALL( p, PauseAll )( p )
#define IAddonDownloadLogic_LaunchTask( p, a )		    IAddonDownloadLogic_CALL( p, LaunchTask )( p, a )
#define IAddonDownloadLogic_Save( p )		            IAddonDownloadLogic_CALL( p, Save )( p )
#define IAddonDownloadLogic_OpenPreChapter( p, a )	    IAddonDownloadLogic_CALL( p, OpenPreChapter )( p, a )
#define IAddonDownloadLogic_OpenNextChapter( p, a )     IAddonDownloadLogic_CALL( p, OpenNextChapter )( p, a )
#define IAddonDownloadLogic_OpenLocalNextChapter( p, a )     IAddonDownloadLogic_CALL( p, OpenLocalNextChapter )( p, a )
#define IAddonDownloadLogic_LoadNextChapter( p, a )     IAddonDownloadLogic_CALL( p, LoadNextChapter )( p, a )
#define IAddonDownloadLogic_CancelOnline( p )		    IAddonDownloadLogic_CALL( p, CancelOnline )( p )
#define IAddonDownloadLogic_CancelImageDownload( p )    IAddonDownloadLogic_CALL( p, CancelImageDownload )( p )
#define IAddonDownloadLogic_OpenCurrentChapter( p )     IAddonDownloadLogic_CALL( p, OpenCurrentChapter )( p )
#define IAddonDownloadLogic_SetIsDownload( p, a )       IAddonDownloadLogic_CALL( p, SetIsDownload)( p, a )
#define IAddonDownloadLogic_OpenCacheFile( p, a )       IAddonDownloadLogic_CALL( p, OpenCacheFile)( p, a )

#define IAddonDownloadLogic_AddDownloadRequest( p, a ,b)	IAddonDownloadLogic_CALL( p, AddDownloadRequest )( p, a ,b)
#endif /* ADDON_VIEW_H_ */
